<?php include 'app/web_input.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
 <head>

  <meta name="author" content="Rithiur" />
  <meta name="description" content="Command Line Calculator with web interface" />
  <meta name="keywords" content="web command line calculator" />
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

  <title>CliCalc - Command Line Calculator</title>

  <link rel="icon" href="favicon.ico" type="image/x-icon" />
  <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />

  <link rel="stylesheet" type="text/css" href="app/wcc.css" />
  <script type="text/javascript" src="app/js/wcc.js"></script>

 </head>
 <body>

  <!-- Initial lines to output -->
  <div id="lines">
<?php

// Output welcome message if we do not have any input
if (count($output) == 0)
{
	echo
		'<div class="output"><code>',
		trim(file_get_contents('doc/welcome.txt')),
		"\n\n",
		trim(file_get_contents('doc/version.txt')),
		"\n\n",
		"</code></div>\n";
}
// Otherwise ouput all lines from ouput (allows this to work without JS)
else
{
	foreach ($output as $line)
	{
		echo
			'<div class="output"><code>',
			htmlspecialchars($line),
			"</code></div>\n";
	}
}

?>
  </div>

 <!-- The input form -->
  <form method="post" id="inputForm" action="">

   <div id="formArea">
    <input type="hidden" id="sid" name="<?php echo session_name(); ?>" value="<?php echo session_id(); ?>" />

    <span class="leftChar">&gt; </span>
    <input type="text" name="input" id="entry" class="inputField" size="50" />
    <input type="submit" value="Submit" class="submitButton" />
   </div>

  </form>

 <!-- Javascript to run at load time -->
  <script type="text/javascript" src="app/js/client.js"></script>

 <!-- Input history saved in session -->
  <script type="text/javascript">
<?php

$format = "inputHistory.push('%s');\n";

// If we have input history in session, output them
if (isset($_SESSION['history']) && is_array($_SESSION['history']))
{
	foreach (array_values($_SESSION['history']) as $i => $line)
	{
		printf($format, addslashes(htmlspecialchars($line)));
	}
}

?>
  </script>

 </body>
</html>
